#include "stdafx.h"
#include "SpalshDlg.h"
#include "version.h"
#include "XMsgBox.h"
#include "FileHelper.h"
//#include "CodeListUpdate.pb.h"

#include "GoodsManager.h"

CSpalshDlg::CSpalshDlg(): XDlg(_T("LAYOUT:XML_SPLASH_WND")) {
}

CSpalshDlg::~CSpalshDlg() {
}

BOOL CSpalshDlg::OnInitDialog(HWND wndFocus, LPARAM lInitParam) {
    m_flag = HttpClient::create_req_flag();
    loadData(xDB.getCodeVersion());
    
    return FALSE;
}

void CSpalshDlg::DoInit() {

}

LRESULT CSpalshDlg::OnReqCodes(UINT uMsg, WPARAM wParam, LPARAM lParam) {
    loadData(wParam);
    return 0;
}

void CSpalshDlg::OnTimer(UINT_PTR idEvent) {
    __super::OnTimer(idEvent);
}

void CSpalshDlg::loadData(int idx) {
    /*CodeListUpdate_Request reqPB;
    reqPB.set_last_version(idx);
    reqPB.set_size_limit(10000);
    
    xHttpClient.Init(m_hWnd);
    xHttpClient.Post("2000", m_flag, reqPB, [this](const XResponse & resp) {
        if (resp.isOK()) {
    
            CodeListUpdate_Response respo;
            resp.ToMessage(respo);
            if (m_remain_count == 0) {
                m_remain_count = respo.remain_size();
            }
    
            if (respo.update_list_size() > 0) {
                xDB.updateCodes(respo.update_list());
                m_remain_count -= respo.update_list_size();
    
                SOUI::SStringW ssText;
                ssText.Format(L"\r\n ver=%d, size=%d\r\n", xDB.getCodeVersion(), m_remain_count);
                OutputDebugString(ssText);
    
                if (m_remain_count <= 0) {
                    EndDialog(IDOK);
                    xGoodsManager.init();
                } else {
                    PostMessage(WM_REQ_CODES, xDB.getCodeVersion(), m_remain_count);
                }
            } else {
                xGoodsManager.init();
                EndDialog(IDOK);
            }
        }
    });*/
}

